import request from '@/utils/request'
// import instance from '../utils/request'
//登录接口
export const userlogin = ({ username, password }) => {
  return request.post(
    '/user/login',
    {
      username,
      password
    }
    // {header:{
    //   'Content-Type': 'application/json'
    // }}
  )
}
//注册接口
export const userRegisterService = ({
  name,
  username,
  password,
  sexs,
  idCard,
  email,
  phone,
  code
}) => {
  return request.post('/user/register', {
    name,
    username,
    password,
    sexs,
    idCard,
    email,
    phone,
    code
  })
}
//获取验证码接口
export const userRegistercode = ({ email }) => {
  return request.post('/common/sendCode', {
    email
  })
}
//忘记密码,修改密码接口
export const userFogetpassword = ({ username, newPassword, email, code }) => {
  return request.put('/user/changePassword', {
    username,
    newPassword,
    email,
    code
  })
}
//获取用户信息接口
export const userGetInfoService = () => request.get('/user/getUserMsg')
//用户退出接口
export const userexit = () => {
  return request.post('/user/logout', {})
}
//上传图片接口
export const upimage = (file) => {
  // 创建一个 FormData 实例
  const formData = new FormData()
  // 假设 avatar 是一个文件对象，比如来自 <input type="file"> 的 File 对象
  console.log(typeof file)
  formData.append('file', file)
  console.log(formData)
  return request.post('/common/upload', formData)
}
//修改用户信息接口
export const userMessagechange = ({
  name,
  phone,
  idCard,
  username,
  image,
  password,
  sexs,
  code
}) => {
  return request.post('/user/changeMsg', {
    name,
    phone,
    idCard,
    username,
    image,
    password,
    sexs,
    code
  })
}
export const chargemoney = (money) => {
  return request.put(`/user/charge/${money}`)
}
